<?php

$sql = "
select 
	object_name(A.id) 			as TABLE_NAME, 
	A.COLORDER					AS ORDINAL_POSITION,
	col_name(A.id, A.colid) 	as COLUMN_NAME,
	'' 							as COLUMN_COMMENT, /* sysproperties 에 있음*/
	B.name 						as DATA_TYPE, 
	case 
		when B.name = 'numberic' or B.name = 'decimal' then A.PREC + ',' + A.SCALE 
		else A.length
	end							AS DATA_LENGTH,
	A.PREC						AS DATA_PREC,
	A.SCALE						AS DATA_SCALE,
	CASE 
		WHEN  A.isnullable	= 0 THEN '' 
		ELSE 'NULL'
	END 						AS ISNULL, 

	case 
		when A.autoval is not null then 'identity' 
		else '' 
	end 						as OPTIONS, 
	case 
		when A.autoval is not null then 'Y'
		else 'N'
	end							as ISAUTO,
	C.text 						as COLUMN_DEFAULT,
	isnull(
			(
				select xtype from sysobjects 
				where name in (
					select name 
					from sysindexes sys 
					where sys.id = A.id 
						and sys.indid in (
								select indid 
								from sysindexkeys 
								where id = A.id
								and colid = A.colid
						)
				)
				and xtype = 'PK' 
		), '') as PK,
	'' as UQ,
	'' as C
from syscolumns A 
		inner join systypes B on (A.xtype = B.xtype) 
		left outer join syscomments C on (A.cdefault = C.id ) 
		left outer join sysconstraints E on (A.id = E.id and A.colid = E.colid) 
where 
	A.id = OBJECT_ID('{$param['object']}') 
order by 
	A.COLORDER
";

return $sql;

?>